/**
 * 
 */
package co.fitstart.coach.dao;

import java.util.Date;
import java.util.List;

import com.demo2do.core.persistence.annotation.Dynamic;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;

import co.fitstart.entity.principal.Principal;
import co.fitstart.entity.principal.PrincipalMessage;

/**
 * @author downpour
 *
 */
@Dynamic("hibernate")
public interface MessageDao {
    
    /**
     * count new message
     * 
     * @param principal
     * @param firstMonthDay
     * @return
     */
    @Query("SELECT COUNT(*) FROM PrincipalMessage WHERE disabled = false and read = false AND createTime >= :firstMonthDay AND principal = :principal")
    public int countNewMessage(@Variable("principal")Principal principal, @Variable("firstMonthDay")Date firstMonthDay);
    
    /**
     * list messages
     * 
     * @param principal
     * @param firstMonthDay
     * @return
     */
    @Query("FROM PrincipalMessage WHERE createTime >= :firstMonthDay AND principal = :principal ORDER BY createTime DESC")
    public List<PrincipalMessage> list(@Variable("principal")Principal principal, @Variable("firstMonthDay")Date firstMonthDay);

}
